package osc.ashye.sharelist;

import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

/**
 * Accept share action intent and handle share action
 */
public class AcceptShareRequestActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_accept_share_request);

        getShareData();
    }

    private void getShareData() {
        Intent shareReq = getIntent();
        String action = shareReq.getAction();
        String type = shareReq.getType();

        if (Intent.ACTION_SEND.equals(action) && type != null) {
            if ("text/plain".equals(type)) {
                handleShareText(shareReq);
            }else if (type.startsWith("image/")) {
                handleShareImage(shareReq);
            }
        }
    }

    private void handleShareText(Intent req) {
        Toast.makeText(this, "share text:" + req.getStringExtra(Intent.EXTRA_TITLE), Toast.LENGTH_SHORT).show();
    }

    private void handleShareImage(Intent req) {
        Toast.makeText(this, "share text:" + req.getStringExtra(Intent.EXTRA_TITLE), Toast.LENGTH_SHORT).show();

    }
}
